package com.brite.android.game.action;


public class Region {
	public float mX;
	public float mY;
	public float mHeight;
	public float mWidth;
	
	public float radius;
	public Cordinate cordinateCenter;
//	
////	public Cordinate cor1, cor2, cor3;
//	
	public int typeRegion;
	public static final int REGION_RECTANGLE = 1; 
	public static final int REGION_CIRCLE = 2;
////	public static final int REGION_TRIANGLE = 3;
	
	public Region(float pX, float pY, float pWidth, float pHeight) {
		typeRegion = REGION_RECTANGLE;
		mX = pX;
		mY = pY;
		mWidth = pWidth;
		mHeight = pHeight;
	}
	
	public Region(float initialRadius, Cordinate initialCordinateCenter) {
		typeRegion = REGION_CIRCLE;
		radius = initialRadius;
		cordinateCenter = initialCordinateCenter;
	}
	
	public boolean isCovered(Cordinate cordinate, Region region){
		switch (region.typeRegion) {
		case REGION_RECTANGLE:
			return isInsideRectange(cordinate, region);
			
		case REGION_CIRCLE:
			return isInsideCircle(cordinate, region);
		}
		return false;
	}
	
	private boolean isInsideRectange(Cordinate cordinate, Region region){
		if (region.mX <= cordinate.x && cordinate.x <= (region.mX + region.mWidth)) {
			if (region.mY <= cordinate.y && cordinate.y <= (region.mY + region.mHeight)) {
				return true;
			}
		}
		return false;
	}
	
	private boolean isInsideCircle(Cordinate cordinate, Region region){
		if (calDistance(region.cordinateCenter.x, region.cordinateCenter.y, cordinate.x, cordinate.y) <= region.radius) {
			return true;
		}
		return false;
	}
	
	private float calDistance(float x0, float y0, float x1, float y1){
		return (float)Math.sqrt((x0-x1)*(x0-x1) +(y0-y1)*(y0-y1));
	}
}
